package com.zjitc.pigspring.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zjitc.pigspring.bean.po.Shop;
import com.zjitc.pigspring.bean.po.ShopVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShopMapper extends BaseMapper<Shop> {

    @Select("select user.name as username,goods.unit as goodUnit,goods.seller_id as sellerId,shop.good_id as goodId,shop.id as id,goods.`name` as goodName,goods.img as goodImg," +
            "seller.`name` as sellerName,shop.user_id as userId,goods.price as goodPrice" +
            " from shop left join goods on shop.good_id=goods.id left join seller " +
            "on goods.seller_id=seller.id left join user on shop.user_id = user.id")
    List<ShopVO> getAll();

    @Select("select goods.seller_id as sellerId,shop.good_id as goodId,shop.id as id,goods.`name` as goodName,goods.img as goodImg," +
            "seller.`name` as sellerName,shop.user_id as userId,goods.price as goodPrice,goods.unit as goodUnit " +
            " from shop left join goods on shop.good_id=goods.id left join seller " +
            "on goods.seller_id=seller.id where shop.user_id = #{id};")
    List<ShopVO> getAllByUser(Integer id);

    @Select("select user.name as username,goods.unit as goodUnit,goods.seller_id as sellerId,shop.good_id as goodId,shop.id as id,goods.`name` as goodName,goods.img as goodImg," +
            "seller.`name` as sellerName,shop.user_id as userId,goods.price as goodPrice" +
            " from shop left join goods on shop.good_id=goods.id left join seller " +
            "on goods.seller_id=seller.id left join user on shop.user_id = user.id where goods.name LIKE CONCAT('%', #{goodName}, '%') ")
    List<ShopVO> selectByShop(ShopVO shopVO);

    @Delete("delete from shop where good_id = #{id}")
    boolean deleteByGoodId(Integer id);

    @Delete("delete from shop where user_id = #{id}")
    boolean deleteByUserId(Integer id);
}
